package divinity.worlds 
{

	import flash.events.*;
	import flash.geom.Point;
	import flash.text.TextField;
	
	import divinity.basic.*;
	import divinity.events.WorldEvent;
	import divinity.fx.display.DisplayFX;
	import divinity.fx.particles.ParticleGenerator;
	import divinity.objects.*;
	import divinity.physics.Wind;
	import divinity.weapons.*;
	
	public class NewWorld extends DivinityWorld
	{
		private var _container:DivinityObject;
		private var player:ControllableObject;
		private var ally:Array=[];;
		private var test:ActiveObject;
		
		
		public function NewWorld(g:*=null)
		{
			super(g);
				
			_terrain=new path();
			createPlayer();			
			addDisplay();
			
			sunAngle=45;
			timeFactor=1;
			gravity=0;
			wind=new Wind(1,.2,500);
		
			
		}
		private function createPlayer()
		{
			player=new ControllableObject(this);
			
			player.mass=1;
			player.x=510;
			player.y=190;
			player.img=new playerimage();
			
			
			
			/*test=new ActiveObject();
			test.world=this;
			test.name="test object";
			test.mass=10;
			test.x=500;
			test.y=200;
			test.img=new playerimage();*/
			
			/*ally[0]=new ControllableObject(this);
			ally[0].mass=0;
			ally[0].x=400;
			ally[0].y=200;
			ally[0].scaleX=1.4;
			ally[0].scaleY=1.4;
			ally[0].img=new playerimage();
			
			ally[1]=new ControllableObject(this);
			ally[1].mass=0;
			ally[1].x=470;
			ally[1].y=140;
			//ally[1].scaleX=1.4;
			//ally[1].scaleY=1.4;
			ally[1].img=new playerimage();
			
			*/
			
			
		}
		private function addDisplay()
		{		
			BACKGROUND.addChild(GOD.mapa);
		
			OBJECTS.addChild(player);		
			SCENE.scaleX=1;
			SCENE.scaleY=1;
			
			DISPLAY.centerOn(player);
			
		}
		override public function init(e:Event)
		{
			super.init(e);			
			startWorld();
			SCENE.addEventListener(MouseEvent.MOUSE_DOWN,movePlayer);	
			//SCENE.addEventListener(MouseEvent.MI,dragDisplay);
			//SCENE.addEventListener(MouseEvent.MIDDLE_MOUSE_UP,dontDragDisplay);
			addEventListener(WorldEvent.UPDATE,setlog);
			stage.addEventListener(KeyboardEvent.KEY_DOWN,kDown);
			//stage.addEventListener(KeyboardEvent.KEY_UP,kUp);
			
		}
		private function dragDisplay(e:MouseEvent)
		{
			SCENE.startDrag();	
		}
		private function dontDragDisplay(e:MouseEvent)
		{
			SCENE.stopDrag();	
		}
		private function movePlayer(e:MouseEvent)
		{
			//player.moveDestionation(SCENE.mouseX,SCENE.mouseY);
		}
		private function kDown(e:KeyboardEvent)
		{
			if(e.keyCode==32)
			{
				fireWeapon();
			}
		}
		private function fireWeapon()
		{
			var me=player;			
			var mouse:Point=new Point(SCENE.mouseX,SCENE.mouseY);			
			var filip:Weapon=new ParticleWeapon(this,me,mouse);				
			VFX.addChild(filip);
			
			/*
			me=ally[0];				
			var filip1:Weapon=new PlasmaWeapon(this,me,mouse);				
			VFX.addChild(filip1);
			
			me=ally[1];				
			var filip2:Weapon=new BeamWeapon(this,me,mouse);				
			VFX.addChild(filip2);*/
			
			
			
			dispatchEvent(new WorldEvent(WorldEvent.UPDATE));
		}
		private function setlog(e:Event)
		{
			//log_txt.text=log;
			//log_txt.scrollV=log_txt.maxScrollV;
		}
		
	}
}